'use strict';

var _promise = require('babel-runtime/core-js/promise');

var _promise2 = _interopRequireDefault(_promise);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var qiniu = require("qiniu");
var accessKey = 'klKD7OL-R07Ri91Zr_0xCFE40_bk2BZFdFf4mz3_';
var secretKey = 'htg-of0AgKGM_XDL8PjvUUC7Pf_Q_xpfvuD0nnab';
var options = {
    scope: 'xmplus',
    expires: 7200,
    returnBody: '{' + '"name": $(fname),' + '"size": $(fsize),' + '"w": $(imageInfo.width),' + '"h": $(imageInfo.height),' + '"hash": $(etag)' + '}'

};
//基础配置
var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
var putPolicy = new qiniu.rs.PutPolicy(options);
var uploadToken = putPolicy.uploadToken(mac);

//获取文件信息
var config = new qiniu.conf.Config();
config.zone = qiniu.zone.Zone_z0;
//创建BucketManager对象
var bucketManager = new qiniu.rs.BucketManager(mac, config);

var bucket = "xmplus";
var key = "1501872375328image-345b65c9-80dc-43ac-8294-17c4a0fb7ccc.jpg";
var bucketManagerResult = bucketManager.stat(bucket, key, function (err, respBody, respInfo) {
    return new _promise2.default(function (resolver, reject) {
        if (err) {
            console.log(err);
            //throw err;
        } else {
            if (respInfo.statusCode == 200) {
                resolver(respBody);
            } else {
                resolver(respBody);
            }
        }
    });
});
exports.bucketResult;

exports.token = uploadToken;